//
//  SettingsViewController.swift
//  GitTFGUI
//
//  Created by Samuel Richard Magny on 2015-08-30.
//  Copyright (c) 2015 Samuel Richard Magny. All rights reserved.
//

import Cocoa

class SettingsViewController: NSViewController, NSTextFieldDelegate {

    @IBOutlet var userNameTextField: NSTextField!
    @IBOutlet var passwordTextField: NSTextField!
    @IBOutlet var emailTextField: NSTextField!
    
    static let StoryboardId:String = "SettingsViewController"
    
    private var tfsClient:ExtendedTFSClient?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        tfsClient = (NSApplication.sharedApplication().delegate as! AppDelegate).tfsClient
        
        userNameTextField.delegate = self
        passwordTextField.delegate = self
        emailTextField.delegate = self
        
        userNameTextField.stringValue = tfsClient!.username
        passwordTextField.stringValue = tfsClient!.password
        emailTextField.stringValue = tfsClient!.email
    }
    
    
    //NSTextFieldDelegate
    override func controlTextDidChange(aNotification: NSNotification) {
        
        if(aNotification.object! as! NSObject == self.userNameTextField) {
            tfsClient!.username = userNameTextField.stringValue
        }
        else if(aNotification.object! as! NSObject == self.passwordTextField) {
            tfsClient!.password = passwordTextField.stringValue
        }
        else if(aNotification.object! as! NSObject == self.emailTextField) {
            tfsClient!.email = emailTextField.stringValue
        }
       
        
    }
    
}
